home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / m2 / cat3src / magic / d / filesys.d next >
Text File  |  1997-10-26  |  19KB  |  411 lines

  1. DEFINITION MODULE FileSys;
  2.  
  3. (*==============================================================*
  4.  *                                                              *
  5.  * Mint-Binding fr Megamax Modula-2, unter Benutzung der       *
  6.  * MagicLib von Peter Hellinger.                                *
  7.  *                                                              *
  8.  * (c) 1992 Dirk Steins                                         *
  9.  *                                                              *
  10.  * Dieses Modul ist Freeware!                                   *
  11.  *                                                              *
  12.  *==============================================================*
  13.  * Autor:               Dirk Steins                             *
  14.  * erstellt am:         13.8.1992                               *
  15.  * letzte Žnderung am:  13.8.1992                               *
  16.  * Version:             1.0                                     *
  17.  *==============================================================*
  18.  * Datum    Vers. Autor     Žnderung (Arbeitsbericht)           *
  19.  *==============================================================*
  20.  *
  21.  * 13.8.92  1.0   DS        Modul erstellt
  22.  *
  23.  *==============================================================*)
  24.  
  25. FROM SYSTEM     IMPORT BYTE, ADDRESS;
  26. FROM MagicSys   IMPORT sCARDINAL, lCARDINAL, sINTEGER, lINTEGER, sBITSET, lBITSET,
  27.                        Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8, Bit9,
  28.                        Bit10, Bit11, Bit12, Bit13, Bit14, Bit15;
  29.  
  30. CONST
  31.         TOS_SEARCH     = 0;      (* Bit 0 in flags by DIR *)
  32.         
  33. (* file types *)
  34.         S_IFMT  = 0170000;     (* mask to select file type *)
  35.         S_IFCHR = 0020000;     (* BIOS special file *)
  36.         S_IFDIR = 0040000;     (* directory file *)
  37.         S_IFREG = 0100000;     (* regular file *)
  38.         S_IFIFO = 0120000;     (* FIFO *)
  39.         S_IMEM  = 0140000;     (* memory region or process *)
  40.         S_IFLNK = 0160000;     (* symbolic link *)
  41.  
  42. (* special bits: setuid, setgid, sticky bit *)
  43.         S_ISUID = 04000;           
  44.         S_ISGID = 02000;           
  45.         S_ISVTX = 01000;           
  46.  
  47. (* file access modes for user, group, and other*)
  48.         S_IRUSR = 0400; 
  49.         S_IWUSR = 0200; 
  50.         S_IXUSR = 0100; 
  51.         S_IRGRP = 0040; 
  52.         S_IWGRP = 0020; 
  53.         S_IXGRP = 0010; 
  54.         S_IROTH = 0004; 
  55.         S_IWOTH = 0002; 
  56.         S_IXOTH = 0001; 
  57.         DEFAULT_DIRMODE = 0777;
  58.         DEFAULT_MODE    = 0666;
  59.  
  60. (* file locking *)
  61.         F_RDLCK     = (* O_RDONLY*) 1;
  62.         F_WRLCK     = (* O_WRONLY *) 2;
  63.         F_UNLCK     = 3;
  64.  
  65.         FS_KNOPARSE = 0;        (* kernel shouldn't do parsing *)
  66.         FS_CASESENSITIVE = 1;   (* file names are case sensitive *)
  67.         FS_NOXBIT   = 2;        (* if a file can be read, it can be executed *)
  68.  
  69. TYPE    
  70.  
  71.         FILESYSPTR = POINTER TO FILESYS;
  72.  
  73.         DEVDRVPTR= POINTER TO DEVDRV;
  74.  
  75.         FILEPTR    = POINTER TO FILE;
  76.         
  77.         DIRPTR     = POINTER TO DIR;
  78.         
  79.         FCOOKIEPTR = POINTER TO FCOOKIE;
  80.         
  81.         FCOOKIE  = RECORD
  82.                      fs    : FILESYSPTR;
  83.                      dev   : sCARDINAL;
  84.                      aux   : sCARDINAL;
  85.                      index : lINTEGER;
  86.                    END;
  87.         
  88.         DIR      = RECORD
  89.                      fc     : FCOOKIE;
  90.                      index  : sCARDINAL;
  91.                      flags  : sBITSET;
  92.                      fsstuff: ARRAY [0..59] OF BYTE;
  93.                    END;
  94.        
  95.         XATTR    = RECORD
  96.                      mode   : sCARDINAL; (* oder sBITSET *)
  97.                      index  : lINTEGER; 
  98.                      dev    : sCARDINAL;
  99.                      reserved1 : sCARDINAL;
  100.                      nlink  : sCARDINAL;
  101.                      uid    : sCARDINAL;
  102.                      gid    : sCARDINAL;
  103.                      size   : lINTEGER;
  104.                      blksize: lINTEGER;
  105.                      nblocks: lINTEGER;
  106.                      mtime,
  107.                      mdate  : sINTEGER;
  108.                      atime,
  109.                      adate  : sINTEGER;
  110.                      ctime,
  111.                      cdate  : sINTEGER;
  112.                      attr   : sINTEGER;
  113.                      reserved2 : sINTEGER;
  114.                      reserved3 : ARRAY [0..1] OF lINTEGER;
  115.                    END;
  116.        
  117.         FILE     = RECORD
  118.                      links  : sINTEGER;  (* number of copies of this descriptor *)
  119.                      flags  : sBITSET;   (* file open mode and other file flags *)
  120.                      pos    : lINTEGER;  (* position in file *)
  121.                      devinfo: lINTEGER;  (* device driver specific info *)
  122.                      fc     : FCOOKIE;   (* file system cookie for this file *)
  123.                      dev    : DEVDRVPTR; (* device driver that knows how to deal with this *)
  124.                      next   : FILEPTR;   (* link to next fileptr for this file *)
  125.                    END;
  126.       
  127.       (* lock structure *)
  128.         FLOCK    = RECORD
  129.                      l_type : sINTEGER;  (* type of lock *)
  130.                      l_whence: sINTEGER; (* SEEK_SET, SEEK_CUR, SEEK_END *)
  131.                      l_start: lINTEGER;  (* start of locked region *)
  132.                      l_len  : lINTEGER;  (* length of locked region *)
  133.                      l_pid  : sINTEGER;  (* pid of locking process
  134.                         (F_GETLK only) *)
  135.                    END;
  136.  
  137. (* LOCK structure used by the kernel internally *)
  138.  
  139.         iLOCK    = POINTER TO LOCK;
  140.         LOCK     = RECORD
  141.                      l      : FLOCK;
  142.                      next   : iLOCK;
  143.                      reserved : ARRAY [0..3] OF lINTEGER;
  144.                    END;
  145.       
  146.         DEVDRV   = RECORD
  147.                      open   : PROCEDURE (FILEPTR) : lINTEGER;
  148.                      write  : PROCEDURE (FILEPTR, ADDRESS, lINTEGER) : lINTEGER;
  149.                      read   : PROCEDURE (FILEPTR, ADDRESS, lINTEGER) : lINTEGER;
  150.                      lseek  : PROCEDURE (FILEPTR, sINTEGER, sINTEGER): lINTEGER;
  151.                      ioctl  : PROCEDURE (FILEPTR, sINTEGER, ADDRESS) : lINTEGER;
  152.                      datime : PROCEDURE (FILEPTR, VAR sINTEGER, BOOLEAN) : lINTEGER;
  153.                      close  : PROCEDURE (FILEPTR, sINTEGER) : lINTEGER;
  154.                      select : PROCEDURE (FILEPTR, lINTEGER, sINTEGER) : lINTEGER;
  155.                      unselect: PROCEDURE (FILEPTR, lINTEGER, sINTEGER): lINTEGER;
  156.                      reserved: ARRAY [0..3] OF lINTEGER;
  157.                    END;
  158.         
  159.         FILESYS  = RECORD
  160.                      next       : FILESYSPTR;   (* link to next file system on chain *)
  161.                      fsflags    : lBITSET;
  162.                      root       : PROCEDURE (sINTEGER, VAR FCOOKIE): lINTEGER;
  163.                      lookup     : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, VAR FCOOKIE): lINTEGER;
  164.                      creat      : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, sINTEGER,
  165.                                              sBITSET, VAR FCOOKIE): lINTEGER;
  166.                      getdev     : PROCEDURE (FCOOKIEPTR, ADDRESS) : DEVDRVPTR;
  167.                      getxattr   : PROCEDURE (FCOOKIEPTR, VAR XATTR): lINTEGER;
  168.                      chattr     : PROCEDURE (FCOOKIEPTR, sBITSET): lINTEGER;
  169.                      chown      : PROCEDURE (FCOOKIEPTR, sINTEGER, sINTEGER): lINTEGER;
  170.                      chmode     : PROCEDURE (FCOOKIEPTR, sINTEGER): lINTEGER;
  171.                      mkdir      : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, sINTEGER): lINTEGER;
  172.                      rmdir      : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
  173.                      remove     : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
  174.                      getname    : PROCEDURE (FCOOKIEPTR, VAR FCOOKIE, VAR ARRAY OF CHAR): lINTEGER;
  175.                      rename     : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
  176.                      opendir    : PROCEDURE (VAR DIR, sINTEGER): lINTEGER;
  177.                      readdir    : PROCEDURE (DIRPTR, ADDRESS, sINTEGER, VAR FCOOKIE): lINTEGER;
  178.                      rewinddir  : PROCEDURE (DIRPTR): lINTEGER;
  179.                      closedir   : PROCEDURE (DIRPTR): lINTEGER;
  180.                      pathconf   : PROCEDURE (FCOOKIEPTR, sINTEGER): lINTEGER;
  181.                      dfree      : PROCEDURE (FCOOKIEPTR, ADDRESS);
  182.                      writelabel : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
  183.                      readlabel  : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER): lINTEGER;
  184.                      symlink    : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, REF ARRAY OF CHAR): lINTEGER;
  185.                      readlink   : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER): lINTEGER;
  186.                      hardlink   : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
  187.                      fscntl     : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER, lINTEGER): lINTEGER;
  188.                      dskchng    : PROCEDURE (sINTEGER): lINTEGER;
  189.                      zero       : PROCEDURE (): lINTEGER;
  190.                    END;
  191.  
  192. CONST
  193. (* flags for open() modes *)
  194.     O_RWMODE    = sBITSET(3);   (* isolates file read/write mode *)
  195.     O_RDONLY    = {}  ; 
  196.     O_WRONLY    = Bit0  ; 
  197.     O_RDWR      = sBITSET(2); 
  198.     O_EXEC      = sBITSET(3);   (* execute file; used by kernel only *)
  199.  
  200.     O_APPEND    = Bit3     ;   (* all writes go to end of file *)
  201.  
  202.     O_SHMODE    = sBITSET($70)  ;     (* isolates file sharing mode *)
  203.     O_COMPAT    = {};                 (* compatibility mode *)
  204.     O_DENYRW    = Bit4  ;     (* deny both read and write access *)
  205.     O_DENYW     = Bit5  ;     (* deny write access to others *)
  206.     O_DENYR     = sBITSET($30)  ;     (* deny read access to others *)
  207.     O_DENYNONE  = Bit6  ;     (* don't deny any access to others *)
  208.  
  209.     O_NOINHERIT = Bit7  ;   (* children don't get this file descriptor *)
  210.  
  211.     O_NDELAY    = Bit8 ;    (* don't block for i/o on this file *)
  212.     O_CREAT     = Bit9 ;    (* create file if it doesn't exist *)
  213.     O_TRUNC     = Bit10 ;   (* truncate file to 0 bytes if it does exist *)
  214.     O_EXCL      = Bit11 ;   (* fail open if file exists *)
  215.  
  216.     O_USER      = sBITSET($0fff);   (* isolates user-settable flag bits *)
  217.  
  218.     O_GLOBAL    = Bit12 ;   (* for Fopen: opens a global file handle *)
  219.  
  220. (* kernel mode bits --  the user can't set these! *)
  221.     O_TTY       = Bit13;   (* FILEPTR refers to a terminal *)
  222.     O_HEAD      = Bit14;   (* FILEPTR is the master side of a fifo *)
  223.     O_LOCK      = Bit15;   (* FILEPTR has had locking Fcntl's performed *)
  224.  
  225.  
  226. (* GEMDOS file attributes *)
  227.  
  228. (* macros to be applied to FILEPTRS to determine their type *)
  229. (*    is_terminal(f) (f->flags & O_TTY) *)
  230.  
  231. (* lseek() origins *)
  232.     SEEK_SET    = 0;       (* from beginning of file *)
  233.     SEEK_CUR    = 1;       (* from current location *)
  234.     SEEK_END    = 2;       (* from end of file *)
  235.  
  236. (* The requests for Dpathconf() *)
  237.     DP_IOPEN       = 0;   (* internal limit on # of open files *)
  238.     DP_MAXLINKS    = 1;   (* max number of hard links to a file *)
  239.     DP_PATHMAX     = 2;   (* max path name length *)
  240.     DP_NAMEMAX     = 3;   (* max length of an individual file name *)
  241.     DP_ATOMIC      = 4;   (* # of bytes that can be written atomically *)
  242.     DP_TRUNC       = 5;   (* file name truncation behavior *)
  243.     DP_NOTRUNC     = 0;   (* long filenames give an error *)
  244.     DP_AUTOTRUNC   = 1;   (* long filenames truncated *)
  245.     DP_DOSTRUNC    = 2;   (* DOS truncation rules in effect *)
  246.     DP_CASE        = 6;   (* file name case conversion behavior *)
  247.     DP_CASESENS    = 0;   (* case sensitive *)
  248.     DP_CASECONV    = 1;   (* case always converted *)
  249.     DP_CASEINSENS  = 2;   (* case insensitive, preserved *)
  250.  
  251.     DP_MAXREQ      = 6;   (* highest legal request *)
  252.  
  253. (* Dpathconf and Sysconf return this when a value is not limited
  254.    (or is limited only by available memory) *)
  255.  
  256.     UNLIMITED      = $7fffffffL;
  257.  
  258. (* various character constants and defines for TTY's *)
  259.     MiNTEOF     = $0000ff1a;  (* 1a == ^Z *)
  260.  
  261. (* defines for tty_read *)
  262.         RAW     = {};
  263.         COOKED  = Bit0;  
  264.         NOECHO  = {};     
  265.         ECHO    = Bit1;  
  266.         ESCSEQ  = Bit2;        (* cursor keys, etc. get escape sequences *)
  267.  
  268. (* constants for various Fcntl commands *)
  269. (* constants for Fcntl calls *)
  270.         F_DUPFD     = 0;       (* handled by kernel *)
  271.         F_GETFD     = 1;       (* handled by kernel *)
  272.         F_SETFD     = 2;       (* handled by kernel *)
  273.         FD_CLOEXEC  = 1;       (* close on exec flag *)
  274.  
  275.         F_GETFL     = 3;       (* handled by kernel *)
  276.         F_SETFL     = 4;       (* handled by kernel *)
  277.         F_GETLK     = 5;
  278.         F_SETLK     = 6;
  279.  
  280.         FSTAT       = $00004600;  (* (('F'<< 8) | 0) (* handled by kernel *)   *)
  281.         FIONREAD    = $00004601;  (* (('F'<< 8) | 1)                           *)
  282.         FIONWRITE   = $00004602;  (* (('F'<< 8) | 2)                           *)
  283.         TIOCGETP    = $00005400;  (* (('T'<< 8) | 0)                           *)
  284.         TIOCSETP    = $00005401;  (* (('T'<< 8) | 1)                           *)
  285.         TIOCSETN    = TIOCSETP;                                
  286.         TIOCGETC    = $00005402;  (* (('T'<< 8) | 2)                           *)
  287.         TIOCSETC    = $00005403;  (* (('T'<< 8) | 3)                           *)
  288.         TIOCGLTC    = $00005404;  (* (('T'<< 8) | 4)                           *)
  289.         TIOCSLTC    = $00005405;  (* (('T'<< 8) | 5)                           *)
  290.         TIOCGPGRP   = $00005406;  (* (('T'<< 8) | 6)                           *)
  291.         TIOCSPGRP   = $00005407;  (* (('T'<< 8) | 7)                           *)
  292.         TIOCFLUSH   = $00005408;  (* (('T'<< 8) | 8)                           *)
  293.         TIOCSTOP    = $00005409;  (* (('T'<< 8) | 9)                           *)
  294.         TIOCSTART   = $0000540A;  (* (('T'<< 8) | 10)                          *)
  295.         TIOCGWINSZ  = $0000540B;  (* (('T'<< 8) | 11)                          *)
  296.         TIOCSWINSZ  = $0000540C;  (* (('T'<< 8) | 12)                          *)
  297.         TIOCGXKEY   = $0000540D;  (* (('T'<< 8) | 13)                          *)
  298.         TIOCSXKEY   = $0000540E;  (* (('T'<< 8) | 14)                          *)
  299.  
  300.         PPROCADDR   = $00005001;  (* (('P'<< 8) | 1)                           *)
  301.         PBASEADDR   = $00005002;  (* (('P'<< 8) | 2)                           *)
  302.         PCTXTSIZE   = $00005003;  (* (('P'<< 8) | 3)                           *)
  303.         PSETFLAGS   = $00005004;  (* (('P'<< 8) | 4)                           *)
  304.         PGETFLAGS   = $00005005;  (* (('P'<< 8) | 5)                           *)
  305.  
  306.         SHMGETBLK   = $00004D00;  (* (('M'<< 8) | 0)                           *)
  307.         SHMSETBLK   = $00004D01;  (* (('M'<< 8) | 1)                           *)
  308.  
  309. (* terminal control constants (tty.sg_flags) *)
  310.         T_CRMOD     = Bit0;  (* 0x0001 *)
  311.         T_CBREAK    = Bit1;  (* 0x0002 *)
  312.         T_ECHO      = Bit2;  (* 0x0004 *)
  313.         T_RAW       = Bit3;  (* 0x0010 *)
  314.         T_TOS       = Bit4;  (* 0x0080 *)
  315.         T_TOSTOP    = Bit5;  (* 0x0100 *)
  316.         T_XKEY      = Bit6;  (* 0x0200      (* Fread returns escape sequences for
  317.                                                cursor keys, etc. *) *)
  318.  
  319. (* the following are terminal status flags (tty.state) *)
  320. (* (the low byte of tty.state indicates a part of an escape sequence still
  321.  * hasn't been read by Fread, and is an index into that escape sequence)
  322.  *)
  323.         TS_ESC      = $00ff;
  324.         TS_HOLD     = Bit12; (* 0x1000      (* hold (e.g. ^S/^Q) *)   *)
  325.         TS_COOKED   = Bit15; (* 0x8000      (* interpret control chars *) *)
  326.  
  327. (* defines and declarations for Dcntl operations *)
  328.  
  329.         DEV_INSTALL = $de02;
  330.         DEV_NEWBIOS = $de01;
  331.         DEV_NEWTTY  = $de00;
  332.  
  333. (* defines for TOS attribute bytes *)
  334.  
  335.         FA_RDONLY   = Bit0; (* 0x01 *)
  336.         FA_HIDDEN   = Bit1; (* 0x02 *)
  337.         FA_SYSTEM   = Bit2; (* 0x04 *)
  338.         FA_LABEL    = Bit3; (* 0x08 *)
  339.         FA_DIR      = Bit4; (* 0x10 *)
  340.         FA_CHANGED  = Bit5; (* 0x20 *)
  341.  
  342. TYPE    
  343.  
  344.         tchars  = RECORD
  345.                     intrc : CHAR;
  346.                     quitc : CHAR;
  347.                     startc: CHAR;
  348.                     stopc : CHAR;
  349.                     eofc  : CHAR;
  350.                     brkc  : CHAR;
  351.                   END;
  352.         
  353.         ltchars = RECORD
  354.                     suspc   : CHAR;
  355.                     dsuspc  : CHAR;
  356.                     rprntc  : CHAR;
  357.                     flushc  : CHAR;
  358.                     werasc  : CHAR;
  359.                     lnextc  : CHAR;
  360.                   END;
  361.         
  362.         sgttyb  = RECORD
  363.                     ispeed  : CHAR;
  364.                     ospeed  : CHAR;
  365.                     erase   : CHAR;
  366.                     kill    : CHAR;
  367.                     flags   : sBITSET;
  368.                   END;
  369.         
  370.         winsize = RECORD
  371.                     ws_row  : sINTEGER;
  372.                     ws_col  : sINTEGER;
  373.                     ws_xpixel : sINTEGER;
  374.                     ws_ypixel : sINTEGER;
  375.                   END;
  376.                   
  377.         xKey    = RECORD
  378.                     xk_num  : sINTEGER;
  379.                     xk_def  : ARRAY [0..7] OF CHAR;
  380.                   END;
  381.         
  382.         xKeyPtr = POINTER TO ARRAY [0..$FFFF] OF xKey;
  383.                   
  384.         TTY     = RECORD
  385.                     pgrp    : sINTEGER;     (* process group of terminal *)
  386.                     state   : sINTEGER;     (* terminal status, e.g. stopped *)
  387.                     use_cnt : sINTEGER;     (* number of times terminal is open *)
  388.                     res1    : sINTEGER;     (* reserved for future expansion    *)
  389.                     sg      : sgttyb;
  390.                     tc      : tchars;
  391.                     ltc     : ltchars;
  392.                     wsiz    : winsize;
  393.                     rsel    : lINTEGER;     (* selecting process for read *)
  394.                     wsel    : lINTEGER;     (* selecting process for write *)
  395.                     xkey    : xKeyPtr;      (* extended keyboard table *)
  396.                     rsrvd   : ARRAY [0..2] OF lINTEGER;
  397.                   END;
  398.         
  399.         ttyPtr  = POINTER TO TTY;
  400.         
  401.         devDescr= RECORD
  402.                     driver  : DEVDRVPTR;
  403.                     dinfo   : sINTEGER;
  404.                     flags   : sINTEGER;
  405.                     tty     : ttyPtr;
  406.                     reserved: ARRAY [0..3] OF CHAR;
  407.                   END;
  408.         
  409.         
  410. END FileSys.
  411.